// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
if (Number.parseInt === undefined) Number.parseInt = window.parseInt;
if (Number.parseFloat === undefined) Number.parseFloat = window.parseFloat;
import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import router from './router'
import $ from 'jquery'
import VueCookies from 'vue-cookies'
Vue.use(VueCookies)
Vue.config.productionTip = false
import Left from '@/plugIn/Left'
import Top from '@/plugIn/Top'
import Router from '@/plugIn/Router'
import Content from '@/plugIn/Content'
import plug from '@/plug'
plug(Vue);
Vue.component('Left', Left);
Vue.component('Top', Top);
Vue.component('Router', Router);
Vue.component('Content', Content);
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  data: {
    router: [],
    user:null,
    Url:'http://81.71.136.172:8082'
  },
  components: {
    App
  },
  methods:{
    setcss(num){
      setTimeout(function(){
        var zong = 0;
        // console.log($('.routerwid p').length)
        for (var i=0;i<$('.routerwid p').length;i++){
          var o = $('.routerwid p').eq(i);
          zong+=o.width();
        }
        $('.routerwid').width(zong);


        var winw = $('.Router>div').width();
        if(num || num == 0){
          var erea = Math.floor(($('.routerwid p').eq(num).position().left - 40)/winw);
          // console.log(erea,$('.routerwid p').eq(num).position().left)
          $('.routerwid').stop().animate({marginLeft:-winw * erea + 'px'},300);
        };
        $('.Router>img').unbind('click');
        $('.Router>img').click(function(){
          var index = $(this).index();
          var nowleft = parseInt($('.routerwid').css('margin-left'));
          if($('.routerwid').width()<winw) return;
          if(index == 1){
              if(($('.routerwid').width() + nowleft) < winw) return;
              $('.routerwid').stop().animate({marginLeft:nowleft-winw + 'px'},300);
          }else{
              if(nowleft>=0) return;
              $('.routerwid').stop().animate({marginLeft:nowleft+winw + 'px'},300);
          }
        })
      },200);
    }
  },
  mounted() {
    var _this = this;
    window.onresize= function(){
      $('.routerwid').animate({marginLeft:'0px'},0);
      _this.setcss();
    }
  },
  template: '<App/>'
})
